<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品名称">
              <a-input placeholder="请输入商品名称" v-model="queryParam.productName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料编码">
              <a-input placeholder="请输入物料编码" v-model="queryParam.skuCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item
              label="渠道">
              <a-select
                v-decorator="[ 'channelId', {}]"
                v-model="queryParam.channelId"
                style="width: 100%"
                :getPopupContainer="node => node.parentNode"
                placeholder="请选择渠道">
                <a-select-option v-for="(channel,channelIdIndex) in optChannelList" :key="channel.id.toString()"
                                 :value="channel.channelId">
                  {{ channel.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('渠道价格列表')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <stmChannelPrice-modal ref="modalForm" @ok="modalFormOk"></stmChannelPrice-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import StmChannelPriceModal from './modules/StmChannelPriceModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {getAction} from "@api/manage";

export default {
  name: "StmChannelPriceList",
  mixins: [JeecgListMixin],
  components: {
    StmChannelPriceModal
  },
  data() {
    return {
      description: '产品价格管理页面',
      optChannelList: [],
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '渠道',
          align: "center",
          dataIndex: 'channelName'
        },
        {
          title: '商品名称',
          align: "center",
          dataIndex: 'productName'
        },
        {
          title: '箱规',
          align: "center",
          dataIndex: 'boxUnit'
        },
        {
          title: '物料编码',
          align: "center",
          dataIndex: 'skuCode'
        },
        {
          title: '价格',
          align: "center",
          dataIndex: 'price'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status_dictText'
        }
      ],
      url: {
        list: "/stm/stmChannelPrice/channelPriceList",
        delete: "/stm/stmChannelPrice/delete",
        deleteBatch: "/stm/stmChannelPrice/deleteBatch",
        exportXlsUrl: "stm/stmChannelPrice/exportXls",
        importExcelUrl: "stm/stmChannelPrice/importExcel",
        channelListUrl: 'stm/stmChannelInfo/list',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  created() {
    this.getChannelList();
  },
  methods: {
    getChannelList() {
      let param = {};
      param.status = 1;
      param.pageSize = 100;
      getAction(this.url.channelListUrl, param).then(res => {
        if (res.success) {
          this.optChannelList = res.result.records;
          this.optChannelList.push({id: "", name: "请选择渠道"})
          this.optChannelList.reverse();
        } else {
          console.log(res.message)
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>